<template>
	<section>
		<!--Alert提示框-->
        <el-alert type="warning" class="alert-style" v-show="hasAlert" @close="fnAlertClose">{{alertMsg}}</el-alert>
		
		<!--工具条-->
		<el-col :span="24" class="toolbar" v-show="hasManufAdd" style="padding-bottom:0px;height: 56px;">
			<el-form :inline="true" :model="filters">
				<!--<el-form-item>
					<el-input v-model="filters.name" placeholder="请输入公司名称"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary">查询</el-button>
				</el-form-item>-->
				<el-form-item>
				 	<el-button type="warning" @click.native="fnAddParentManuf">新增工艺分类</el-button>
				</el-form-item>
			</el-form>
		</el-col>
		
		<!--列表-->
		<tree-table :columns="columns" :tree-structure="true" :data-source="manufactures" v-loading="manufacturesLoading" element-loading-text="拼命加载中" style="margin-top: 10px;"></tree-table>
		
	</section>
</template>

<script>
    import Svc from '../../service/index.js'
	export default {
		data() {
			return {
				alertMsg:'',
				hasAlert:false,
				manufacturesLoading:false,
				//工艺列表
			    columns: [
			          {
			            text: '工艺分类Code',
			            dataIndex: 'Code'
			          },
			          {
			            text: '工艺分类名称',
			            dataIndex: 'Value'
			          }
			    ],
			    manufactures: [],
			    //判断当前用户是否拥有新增工艺的权限
  				hasManufAdd : false
		    }  
		},
		methods: {
			//获取制造工艺列表
			fnGetManufacture : function() {
				var that = this
//				var manufactures = sessionStorage.getItem('manufactures');
//				if (manufactures) {
//					that.manufactures = JSON.parse(manufactures)
//				} else {
					//获取制造工艺列表
					that.manufacturesLoading = true
		            Svc.fnGetData('/api/manuf/all',{},function(res){
		            	if (res.body.ErrCode == 0){
		            		that.manufactures = res.body.Data
		            		//保存制造工艺列表
		            		sessionStorage.setItem('manufactures', JSON.stringify(res.body.Data));
		            		that.manufacturesLoading = false
		            	} else {
		            		that.alertMsg = "制造工艺列表获取失败！"
		            		that.hasAlert = true
		            	}
		            },function(res){
		            	that.alertMsg = "网络错误，请重新！"
		            	that.hasAlert = true
		            }) 
//				}
			},
			//新增父级工艺分类
			fnAddParentManuf : function(){
				this.$router.push({path: '/manufdetail', query: {opttype: "newParent"}})
			},
	       	//获取当前用户所拥有的按钮操作权限
	       	fnCheckAction : function(){
	       		var that = this
	       		//新增工艺操作
				Svc.fnPostData('/api/account/authcheck',{Action:'/api/manuf/add',Method:'POST'},function(res){
					that.hasManufAdd = res.body.Data
				})
	       	}
		},
		mounted() {
			//获取制造工艺列表
			this.fnGetManufacture()
		   	//获取当前用户所拥有的按钮操作权限
			this.fnCheckAction()
		}
	}
</script>

<style scoped>
	.toolbar {
	    background: #f2f2f2;
	    padding: 10px 10px 0 10px;
	    margin: 10px 0;
	}
</style>